package com.dhcc.bpm.modules.safe.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dhcc.bpm.common.text.Convert;
import com.dhcc.bpm.modules.safe.entity.OrgaGateway;
import com.dhcc.bpm.modules.safe.mapper.OrgaGatewayMapper;
import com.dhcc.bpm.modules.safe.service.IOrgaGatewayService;
import com.dhcc.bpm.modules.safe.vo.OrgaGatewayVO;
import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName OrgaGatewayServiceImpl
 * @Description 网关访问控制机构关联表 服务实现类
 * @Author daina
 * @Date 2020/2/21 14:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 */
@Service("opc_orga_gateway")
public class OrgaGatewayServiceImpl extends ServiceImpl<OrgaGatewayMapper, OrgaGateway> implements IOrgaGatewayService {

	@Override
	public IPage<OrgaGatewayVO> selectOrgaGatewayPage(IPage<OrgaGatewayVO> page, OrgaGatewayVO orgaGateway) {
		return page.setRecords(baseMapper.selectOrgaGatewayPage(page, orgaGateway));
	}

	@Override
	public Boolean batchControllerOrga(Long opcControlId, String ids) {
		List<Long> orgaIds = Func.toLongList(ids);
		ArrayList<OrgaGateway> list = new ArrayList<>();
		orgaIds.forEach(orgaId->{
			OrgaGateway orgaGateway = new OrgaGateway();
			orgaGateway.setOpcOrgaId(orgaId);
			orgaGateway.setOpcControlId(opcControlId);
			list.add(orgaGateway);
		});
		return saveBatch(list);
	}

	@Override
	public int deleteOrgas(Long opcControlId, String ids) {
		return baseMapper.deleteOrgas(opcControlId,Convert.toLongArray(ids));
	}
}
